Add parsing of GPRMC sentences. From ?yvind Kaurstad (oyvindk)
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 20 Aug 2004 03:07:14 +0000 (03:07 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 20 Aug 2004 03:07:14 +0000 (03:07 +0000)
gpsbabel/nmea.c

index 06ba706f3470f01ab946bbcf9def1f0ff803f710..6f34f4cfbc80279de73ec713c8ad0c889d33bbcd 100644 (file)
    '  6    225444       Fix taken at 22:54:44 UTC
    '  7    A            Data valid
 
+   ' $GPRMC - Recommended minimum specific GNSS Data\r
+   ' $GPRMC,085721.194,A,5917.7210,N,01103.9227,E,21.42,50.33,300504,,*07\r
+   '  2    085721       Fix taken at 08:57:21 UTC\r
+   '  3    A                           Fix valid (this field reads V if fix is not valid)\r
+   '  4,5  5917.7210,N   Latitude 59 deg 17.7210' N\r
+   '  6,7  01103.9227,E  Longitude 11 deg 03.9227' E\r
+   '  8    21.42                       Speed over ground (knots)\r
+   '  9    50.33                       Course over ground (true)\r
+   '   10   300504                     Date 30/05-2004\r
+   '  11   Empty field Magnetic variation\r
+\r
+\r
    ' The optional checksum field consists of a "*" and two hex digits repre-
    ' senting the exclusive OR of all characters between, but not including,
    ' the "$" and "*".  A checksum is required on some sentences.
 ****************************************/
 
 /*
- * An input file mayh have both GGA and GLL sentences for the exact 
- * same position fix.   If we see a single GGA, start ignoring GLL's.
+ * An input file may have both GGA and GLL and RMC sentences for the exact \r
+ * same position fix. If we see a single GGA, start ignoring GLL's and RMC's.\r
+ *     GLL's will also be ignored if RMC's are found and GGA's not found.\r
  */
\r
 typedef enum {
        gp_unknown = 0,
        gpgga,
-       gplgll
+       gplgll,\r
+       gprmc\r
 } preferred_posn_type;
 
 static FILE *file_in;
@@ -212,6 +227,48 @@ gpgga_parse(char *ibuf)
 }
 
 static void
+gprmc_parse(char *ibuf)\r
+{\r
+       double latdeg, lngdeg;\r
+       char lngdir, latdir;\r
+       double hms;\r
+       double speed, course;\r
+       char fix;\r
+       struct tm tm;\r
+       waypoint *waypt;\r
+\r
+       if (trk_head == NULL) {\r
+               trk_head = route_head_alloc();\r
+               track_add_head(trk_head);\r
+       }\r
+\r
+       waypt  = waypt_new();\r
+\r
+       memset(&tm, 0, sizeof(tm));\r
+\r
+       sscanf(ibuf,"$GPRMC,%f,%c,%lf,%c,%lf,%c,%lf,%lf",\r
+               &hms, &fix, &latdeg, &latdir,\r
+               &lngdeg, &lngdir,\r
+               &speed, &course);\r
+\r
+       tm.tm_sec = (long) hms % 100;\r
+       hms = hms / 100;\r
+       tm.tm_min = (long) hms % 100;\r
+       hms = hms / 100;\r
+       tm.tm_hour = (long) hms % 100;\r
+\r
+       waypt->creation_time = mktime(&tm) + get_tz_offset() + current_time();\r
+\r
+       if (latdir == 'S') latdeg = -latdeg;\r
+       waypt->latitude = ddmm2degrees(latdeg);\r
+\r
+       if (lngdir == 'W') lngdeg = -lngdeg;\r
+       waypt->longitude = ddmm2degrees(lngdeg);\r
+\r
+       route_add_wpt(trk_head, waypt);\r
+}\r
+\r
+static void\r
 gpwpl_parse(char *ibuf)
 {
        waypoint *waypt;
@@ -272,8 +329,14 @@ nmea_read(void)
                        posn_type = gpgga;
                        gpgga_parse(ibuf);
                } else
-               if (0 == strncmp(ibuf, "$GPGLL,", 7)) {
+               if (0 == strncmp(ibuf, "$GPRMC,", 7)) {\r
                        if (posn_type != gpgga) {
+                       posn_type = gprmc;\r
+                               gprmc_parse(ibuf);\r
+                       }                       \r
+               } else\r
+               if (0 == strncmp(ibuf, "$GPGLL,", 7)) {\r
+                       if ((posn_type != gpgga) && (posn_type != gprmc)) {\r
                                gpgll_parse(ibuf);
                        }
                } else